<template>
  <div>
    <el-row type="flex" justify="center">
      <el-col :span="6">
        <el-form label-width="80px">
          <el-form-item label="标签名">
            <el-input v-model="name" placeholder="请输入标签名"></el-input>
          </el-form-item>
          <el-form-item label="所属分类">
            <el-select v-model="cate">
              <el-option :value="item.id" :label="item.name" v-for="item in cate_list" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="add">添加</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
    data(){
        return {
            name:"",
            cate:"",
            cate_list:[],
        }
    },
    created(){
        //访问一级分类 
        this.axios.get("/cate").then(resp=>{
            console.log(resp.data)
            this.cate_list=resp.data
        }).catch(error=>{
            console.log(error)
        })
    },
    methods:{
        add(){
            const data={
                name:this.name,
                cate:this.cate,
            }
            this.axios.post("/tag",data).then(resp=>{
                console.log(resp.data)
                this.$message({
                    "message":"添加标签成功",
                    "type":"success",
                })
            }).catch(error=>{
                console.log(error)
                this.$message.error("添加失败")
            })
        }
    }
};
</script>

<style>
</style>